package cn.com.mrzheng.web.controller;

import cn.com.mrzheng.web.entity.QiNiu;
import cn.com.mrzheng.web.utils.AutoKey;
import cn.com.mrzheng.web.utils.ServiceApi;
import com.qiniu.util.Auth;
import org.springframework.web.bind.annotation.*;

@RestController
//  跨域调用
@CrossOrigin(origins = ServiceApi.Config.CrossOrigin, maxAge = 3600)
public class QiNiuController {

    @RequestMapping(value = ServiceApi.QiNiu.Token, method = RequestMethod.POST)
    public QiNiu GetToken(){
            String accessKey = "zxl5VuED2Xpfl8RjIk34jRvUjxf_DGwsXOk8WWya";
            String secretKey = "iI6b3AGfAId0sMf_Qlsta9rDwLf2nRdLPJTsCxXI";
            String bucket = "hongtao2";
            Auth auth = Auth.create(accessKey, secretKey);
            String upToken = auth.uploadToken(bucket);
            QiNiu qiNiu = new QiNiu();
            qiNiu.setToken(upToken);
            qiNiu.setKey(AutoKey.getKey());
            return qiNiu;
    }
}
